package com.xique.park.controller.app;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.park.bean.request.app.*;
import com.xique.park.bean.request.app.ParkCarListRequest;
import com.xique.park.service.biz.service.IParkCarBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 车辆Controller
 *
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/app/car")
public class AppParkCarController extends BaseController {

    @Autowired
    private IParkCarBizService parkCarBizService;

    /**
     * 查询车辆列表
     */
    @PostMapping("/list")
    public AjaxResult parkCarList(@Validated @RequestBody ParkCarListRequest request) {
        return parkCarBizService.getParkCarList(request);
    }

    /**
     * 查询某辆车具体信息
     */
    @GetMapping("/info")
    public AjaxResult getParkCarInfo(Long carId) {
        return parkCarBizService.getParkCarInfo(carId);
    }

    /**
     * 查询某辆车续费页面具体信息
     */
    @GetMapping("/feeInfo")
    public AjaxResult getParkCarFeeInfo(Long carId) {
        return parkCarBizService.getParkCarFeeInfo(carId);
    }

    /**
     * 添加车辆
     */
    @Log(title = "车辆", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addParkCar(@Validated @RequestBody ParkCarAddRequest request) {
        request.setParkId(SecurityUtils.getParkId());
        return parkCarBizService.addParkCar(request);
    }

    /**
     * 编辑车辆
     */
    @Log(title = "车辆", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult editParkCar(@Validated @RequestBody ParkCarEditRequest request) {
        request.setParkId(SecurityUtils.getParkId());
        return parkCarBizService.editParkCar(request);
    }

    /**
     * 车辆续期
     */
    @Log(title = "车辆续期", businessType = BusinessType.UPDATE)
    @PostMapping("/fee")
    public AjaxResult feeParkCar(@Validated @RequestBody ParkCarFeeRequest request) {
        return parkCarBizService.feeParkCar(request);
    }

    /**
     * 删除车辆
     */
    @Log(title = "车辆", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult remove(@Validated @RequestBody ParkCarDeleteRequest request) {
        return parkCarBizService.delParkCar(request);
    }

    /**
     * 校验某个车场车牌的唯一性
     */
    @PostMapping("/checkPlateUnique")
    public AjaxResult checkPlateUnique(@Validated @RequestBody ParkCarUniqueCheckRequest request) {
        return parkCarBizService.checkPlateUnique(request);
    }

    /**
     * 计算月卡车应收金额
     */
    @PostMapping("/calFixedFee")
    public AjaxResult calFixedFee(@Validated @RequestBody ParkCarCalFixedFeeRequest request) {
        return parkCarBizService.calFixedFee(request);
    }

}
